import { request } from '@umijs/max';
import type { MsgResponse, PagedDataResponse } from '../typing';
import type { CommentInfo } from './typing';

/**
 * 分页获取所有评论
 *
 * @param { number } page 页码
 * @param { number } pageSize 页面大小
 * @param { string } commentNickname 评论人(模糊)
 * @param { string } comment 评论(模糊)
 * @returns { PagedDataResponse }
 */
export function getAllComment(params: {
  page: number;
  pageSize: number;
  commentNickname?: string;
  comment?: string;
}) {
  return request<Promise<PagedDataResponse<CommentInfo>>>('/api/comments', {
    method: 'GET',
    params,
  });
}

/**
 * 删除单个评论
 *
 * @param { number } commentId 评论ID
 * @returns { MsgResponse }
 */
export function delSingleComment(commentId: number) {
  return request<MsgResponse>(`/api/comments/${commentId}`, {
    method: 'DELETE',
  });
}

/**
 * 获取文章品论列表
 *
 * @param { number } articleId 文章ID
 * @returns { PagedDataResponse }
 */
export function getArticleComment(articleId: number) {
  return request<PagedDataResponse<CommentInfo>>('/common/comments', {
    method: 'GET',
    params: { articleId },
  });
}
